home *** CD-ROM | disk | FTP | other *** search
/ World of Amiga / World of Amiga.iso / archive / compression / lister12.lha / ListCpio.c < prev    next >
Encoding:
Text File  |  1992-04-01  |  1.2 KB  |  56 lines

  1. /* lists a CPIO file's contents */
  2. BOOL
  3. ListCpio(ULONG type,UBYTE *infile)
  4. {
  5.   int ct, done, i;
  6.   ULONG uncomp, comp, time;
  7.   ULONG tfiles = 0, tcomp = 0, tuncomp = 0;
  8.   UBYTE b[200],time_str[25];
  9.   struct tm *tm;
  10.   FILE *fp;
  11.  
  12.   fp = OpenFile(type,infile);
  13.   ct = fread(b, 76, 1, fp);
  14.  
  15.   /* check CPIO signature */
  16.   if ((strnicmp(CPIO_SIG,b,6) != 0) || ct != 1)
  17.    {
  18.     fclose(fp);
  19.     return(WRONG_ARCHIVE);
  20.    }
  21.  
  22.   /* start listing */
  23.   InitList(CPIO,infile);
  24.  
  25.   /* parse each header block until CPIO signature check fails or EOF */
  26.   done= FALSE;
  27.   while ( ! done) {
  28.     comp = uncomp = Convert8(b+70);
  29.  
  30.     /* get Un*x stored time */
  31.     sscanf (b+48,"%11o",&time);
  32.     tm = localtime (&time);
  33.     sprintf (time_str,"%02d-%s-19%d %02d:%02d:%02d",
  34.       tm->tm_mday,months[tm->tm_mon],tm->tm_year,tm->tm_hour,
  35.       tm->tm_min,tm->tm_sec);
  36.  
  37.     /* get filename */
  38.     i = Convert8(b+59);
  39.     fread(b, (ULONG) i, 1, fp);
  40.     PrintList(b, uncomp, comp,&tfiles,&tcomp,&tuncomp,time_str);
  41.  
  42.     fseek(fp,uncomp,SEEK_CUR);
  43.  
  44.     /* get next block and check */
  45.     ct = fread(b, 76, 1, fp);
  46.     i = Convert8(b+70);
  47.     if ((strnicmp(CPIO_SIG,b,6) != 0) || ct != 1 || i == 0)
  48.       done = TRUE;
  49.     }
  50.  
  51.   fclose(fp);
  52.   EndStats(tfiles,tcomp,tuncomp);
  53.   return(TRUE);
  54. }
  55.  
  56.